/*
 * @Title POI.java
 * poi-xx-xxxxxxxx.jar
 * poi-ooxml-xx-xxxxxxxx.jar
 * poi-ooxml-schemas-xx-xxxxxxxx.jar
 * dom4j-x.x.x.jar
 * xmlbeans-x.x.x.jar
 * @Copyright Copyright(c) 2018
 * @Company com.lizhen
 * @author lizhen
 * @version 0.0.1
 */
package com.lizhen.core.function.poi;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.*;

/**
 * @author lizhen
 */
public class POI {

    private static String FILE_PATH = "1.8\\api\\main\\resource\\com\\lizhen\\core\\function\\poi\\POI\\POI.xlsx";

    /**
     * @author lizhen
     */
    public static void main(String[] args) {
        POICreation.main(null);
        POIOpen.main(null);
    }

    static class POICreation {
        public static void main(String[] args) {
            XSSFWorkbook workbook = new XSSFWorkbook();
            try {
                FileOutputStream fos = new FileOutputStream(new File(FILE_PATH));
                workbook.write(fos);
                fos.close();

                System.out.println("createworkbook.xlsx written successfully");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    static class POIOpen {
        public static void main(String args[]) {
            File file = new File(FILE_PATH);
            try {
                FileInputStream fis = new FileInputStream(file);
                XSSFWorkbook workbook = new XSSFWorkbook(fis);

                if (file.isFile() && file.exists()) {
                    System.out.println("POI.xlsx file open successfully.");
                } else {
                    System.out.println("Error to open POI.xlsx file.");
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
